﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class tbl_Sensor
    {
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT ID,SensorAddress,SensorCode ");
            strSql.Append(" FROM tbl_Sensor ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" Order by SensorAddress ");
            //return DBUnlity.DBHelpSQL.ExeSql(strSql.ToString());
            return DBUnlity.DBHelpSQL.Query(strSql.ToString());
        }


        public DataSet GetAllList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT ID,SensorAddress,SensorCode,LastTemperature,LastHumidity,LastUpdateTime ");
            strSql.Append(" FROM tbl_Sensor ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" Order by SensorAddress ");
            //return DBUnlity.DBHelpSQL.ExeSql(strSql.ToString());
            return DBUnlity.DBHelpSQL.Query(strSql.ToString());
        }




        public DataSet GetMyList(string strwhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT tbl_Sensor.ID, tbl_Sensor.SensorAddress, tbl_Sensor.SensorCode, tbl_Sensor.AreaID, tbl_Sensor.WorkshopID, tbl_Sensor.status, tbl_Area.AreaName, tbl_Workshop.WorkshopName FROM tbl_Sensor LEFT OUTER JOIN tbl_Workshop ON tbl_Sensor.WorkshopID = tbl_Workshop.ID LEFT OUTER JOIN tbl_Area ON tbl_Sensor.AreaID = tbl_Area.ID ");
            if (strwhere.Trim() != "")
            {
                strSql.Append(" where " + strwhere);
            }
            //return DBUnlity.DBHelpSQL.ExeSql(strSql.ToString());
            return DBUnlity.DBHelpSQL.Query(strSql.ToString());

        }


    }
}
